<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改商品</title>
</head>
<body>
<h1>商品修改页面</h1>
<div>
    <!-- readonly 设置为只读-->
    <input type="text" placeholder="id" readonly v-model="product.id">
    <input type="text" placeholder="标题" v-model="product.title">
    <input type="text" placeholder="价格" v-model="product.price">
    <input type="text" placeholder="销量" v-model="product.saleCount">
    <input type="button" value="修改" @click="update()">
</div>
<script src="./js/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
            product:{
                id:"",
                title:"",
                price:"",
                saleCount: ""
            }
        },
        created:function(){
            //页面加载完之后得到商品的id 通过id查询商品信息 并显示到页面中
            //从地址栏中得到id的参数
            let id = location.search.split("=")[1];
            axios.get("/selectById?id="+id).then(function (response) {
                v.product = response.data;
            })
        },
        methods:{
            update(){
                axios.post("/update",v.product).then(function (response) {
                    alert("修改完成");
                    location.href="/list.html";
                })
            }
        }

    })
</script>
</body>
</html>